package com.itcast.googleplay.holder;

import com.itcast.googleplay.R;
import com.itcast.googleplay.domain.CategoryInfo;
import com.itcast.googleplay.http.CZApi;
import com.itcast.googleplay.utils.UIUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class CategoryHolder extends BaseHolder {

	private ImageView image1,image2,image3;
	private TextView tv1,tv2,tv3;
	private DisplayImageOptions options;

	@Override
	public void initData() {
		Object data = getData();
		if(data instanceof CategoryInfo){
			CategoryInfo categoryInfo = (CategoryInfo)data;
			
			
			tv1.setText(categoryInfo.name1);
			tv2.setText(categoryInfo.name2);
			tv3.setText(categoryInfo.name3);
			
			if(!TextUtils.isEmpty(categoryInfo.url1)){
				ImageLoader.getInstance().displayImage(CZApi.BASEIMGURL+categoryInfo.url1, image1, options);
			}
			if(!TextUtils.isEmpty(categoryInfo.url2)){
				ImageLoader.getInstance().displayImage(CZApi.BASEIMGURL+categoryInfo.url2, image2, options);
			}
			if(!TextUtils.isEmpty(categoryInfo.url3)){
				ImageLoader.getInstance().displayImage(CZApi.BASEIMGURL+categoryInfo.url3, image3, options);
			}
		}
	}

	@Override
	public View initView() {
		options = new DisplayImageOptions.Builder()
			.showImageOnLoading(R.drawable.ic_default)//在加载图片的时候,展示的默认图片
			
			.showImageForEmptyUri(R.drawable.ic_default)//uri传递出现问题时展示的图片
			
			.showImageOnFail(R.drawable.ic_default)//加载网络失败的时候,展示的图片
			
			.cacheInMemory(true)//是否需要内存缓存
			
			.cacheOnDisk(true)//是否需要磁盘缓存
			
			.considerExifParams(true)//是否支持图片自动调整,让其正常图像显示
	
			.build();//设置圆角半径
		
		View view = UIUtils.inflate(R.layout.layout_category_item);
		image1 = (ImageView) view.findViewById(R.id.image1);
		image2 = (ImageView)view.findViewById(R.id.image2);
		image3 = (ImageView)view.findViewById(R.id.image3);

		tv1 = (TextView) view.findViewById(R.id.tv1);
		tv2 = (TextView)view.findViewById(R.id.tv2);
		tv3 = (TextView)view.findViewById(R.id.tv3);
		return view;
	}

}
